home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / php / pear / adodb / drivers / adodb-mysqli.inc.php < prev    next >
PHP Script  |  2005-05-17  |  22KB  |  851 lines

  1. <?php
  2. /*
  3. V4.63 17 May 2005  (c) 2000-2005 John Lim (jlim@natsoft.com.my). All rights reserved.
  4.   Released under both BSD license and Lesser GPL library license. 
  5.   Whenever there is any discrepancy between the two licenses, 
  6.   the BSD license will take precedence.
  7.   Set tabs to 8.
  8.   
  9.   MySQL code that does not support transactions. Use mysqlt if you need transactions.
  10.   Requires mysql client. Works on Windows and Unix.
  11.  
  12. 21 October 2003: MySQLi extension implementation by Arjen de Rijke (a.de.rijke@xs4all.nl)
  13. Based on adodb 3.40
  14. */ 
  15.  
  16. // security - hide paths
  17. //if (!defined('ADODB_DIR')) die();
  18.  
  19. if (! defined("_ADODB_MYSQLI_LAYER")) {
  20.  define("_ADODB_MYSQLI_LAYER", 1 );
  21.  
  22.  if (!defined('MYSQLI_READ_DEFAULT_GROUP')) define('MYSQLI_READ_DEFAULT_GROUP',1);
  23.  
  24.  // disable adodb extension - currently incompatible.
  25.  global $ADODB_EXTENSION; $ADODB_EXTENSION = false;
  26.  
  27. class ADODB_mysqli extends ADOConnection {
  28.     var $databaseType = 'mysqli';
  29.     var $dataProvider = 'native';
  30.     var $hasInsertID = true;
  31.     var $hasAffectedRows = true;    
  32.     var $metaTablesSQL = "SHOW TABLES";    
  33.     var $metaColumnsSQL = "SHOW COLUMNS FROM %s";
  34.     var $fmtTimeStamp = "'Y-m-d H:i:s'";
  35.     var $hasLimit = true;
  36.     var $hasMoveFirst = true;
  37.     var $hasGenID = true;
  38.     var $isoDates = true; // accepts dates in ISO format
  39.     var $sysDate = 'CURDATE()';
  40.     var $sysTimeStamp = 'NOW()';
  41.     var $hasTransactions = true;
  42.     var $forceNewConnect = false;
  43.     var $poorAffectedRows = true;
  44.     var $clientFlags = 0;
  45.     var $substr = "substring";
  46.     var $port = false;
  47.     var $socket = false;
  48.     var $_bindInputArray = false;
  49.     var $nameQuote = '`';        /// string to use to quote identifiers and names
  50.     var $optionFlags = array(array(MYSQLI_READ_DEFAULT_GROUP,0));
  51.     
  52.     function ADODB_mysqli() 
  53.     {            
  54.      // if(!extension_loaded("mysqli"))
  55.           ;//trigger_error("You must have the mysqli extension installed.", E_USER_ERROR);
  56.         
  57.     }
  58.     
  59.  
  60.     // returns true or false
  61.     // To add: parameter int $port,
  62.     //         parameter string $socket
  63.     function _connect($argHostname = NULL, 
  64.               $argUsername = NULL, 
  65.               $argPassword = NULL, 
  66.               $argDatabasename = NULL, $persist=false)
  67.       {
  68.            if(!extension_loaded("mysqli")) {
  69.             return null;
  70.          }
  71.         $this->_connectionID = @mysqli_init();
  72.         
  73.         if (is_null($this->_connectionID)) {
  74.           // mysqli_init only fails if insufficient memory
  75.           if ($this->debug) 
  76.                 ADOConnection::outp("mysqli_init() failed : "  . $this->ErrorMsg());
  77.           return false;
  78.         }
  79.         /*
  80.         I suggest a simple fix which would enable adodb and mysqli driver to
  81.         read connection options from the standard mysql configuration file
  82.         /etc/my.cnf - "Bastien Duclaux" <bduclaux#yahoo.com>
  83.         */
  84.         foreach($this->optionFlags as $arr) {    
  85.             mysqli_options($this->_connectionID,$arr[0],$arr[1]);
  86.         }
  87.         
  88.          if (mysqli_real_connect($this->_connectionID,
  89.                      $argHostname,
  90.                      $argUsername,
  91.                      $argPassword,
  92.                      $argDatabasename,
  93.                     $this->port,
  94.                     $this->socket,
  95.                     $this->clientFlags))
  96.            {
  97.          if ($argDatabasename)  return $this->SelectDB($argDatabasename);
  98.           
  99.         
  100.          return true;
  101.         }
  102.          else {
  103.             if ($this->debug) 
  104.                   ADOConnection::outp("Could't connect : "  . $this->ErrorMsg());
  105.             return false;
  106.           }
  107.       }
  108.     
  109.     // returns true or false
  110.     // How to force a persistent connection
  111.     function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  112.     {
  113.         return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename, true);
  114.  
  115.     }
  116.     
  117.     // When is this used? Close old connection first?
  118.     // In _connect(), check $this->forceNewConnect? 
  119.     function _nconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
  120.       {
  121.         $this->forceNewConnect = true;
  122.         return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabasename);
  123.       }
  124.     
  125.     function IfNull( $field, $ifNull ) 
  126.     {
  127.         return " IFNULL($field, $ifNull) "; // if MySQL
  128.     }
  129.     
  130.     function ServerInfo()
  131.     {
  132.         $arr['description'] = $this->GetOne("select version()");
  133.         $arr['version'] = ADOConnection::_findvers($arr['description']);
  134.         return $arr;
  135.     }
  136.     
  137.     
  138.     function BeginTrans()
  139.     {      
  140.         if ($this->transOff) return true;
  141.         $this->transCnt += 1;
  142.         $this->Execute('SET AUTOCOMMIT=0');
  143.         $this->Execute('BEGIN');
  144.         return true;
  145.     }
  146.     
  147.     function CommitTrans($ok=true) 
  148.     {
  149.         if ($this->transOff) return true; 
  150.         if (!$ok) return $this->RollbackTrans();
  151.         
  152.         if ($this->transCnt) $this->transCnt -= 1;
  153.         $this->Execute('COMMIT');
  154.         $this->Execute('SET AUTOCOMMIT=1');
  155.         return true;
  156.     }
  157.     
  158.     function RollbackTrans()
  159.     {
  160.         if ($this->transOff) return true;
  161.         if ($this->transCnt) $this->transCnt -= 1;
  162.         $this->Execute('ROLLBACK');
  163.         $this->Execute('SET AUTOCOMMIT=1');
  164.         return true;
  165.     }
  166.     
  167.     // if magic quotes disabled, use mysql_real_escape_string()
  168.     // From readme.htm:
  169.     // Quotes a string to be sent to the database. The $magic_quotes_enabled
  170.     // parameter may look funny, but the idea is if you are quoting a 
  171.     // string extracted from a POST/GET variable, then 
  172.     // pass get_magic_quotes_gpc() as the second parameter. This will 
  173.     // ensure that the variable is not quoted twice, once by qstr and once 
  174.     // by the magic_quotes_gpc.
  175.     //
  176.     //Eg. $s = $db->qstr(_GET['name'],get_magic_quotes_gpc());
  177.     function qstr($s, $magic_quotes = false)
  178.     {
  179.         if (!$magic_quotes) {
  180.             if (PHP_VERSION >= 5)
  181.                   return "'" . mysqli_real_escape_string($this->_connectionID, $s) . "'";   
  182.         
  183.         if ($this->replaceQuote[0] == '\\')
  184.             $s = adodb_str_replace(array('\\',"\0"),array('\\\\',"\\\0"),$s);
  185.         return  "'".str_replace("'",$this->replaceQuote,$s)."'"; 
  186.       }
  187.       // undo magic quotes for "
  188.       $s = str_replace('\\"','"',$s);
  189.       return "'$s'";
  190.     }
  191.     
  192.     function _insertid()
  193.     {
  194.       $result = @mysqli_insert_id($this->_connectionID);
  195.       if ($result == -1){
  196.           if ($this->debug) ADOConnection::outp("mysqli_insert_id() failed : "  . $this->ErrorMsg());
  197.       }
  198.       return $result;
  199.     }
  200.     
  201.     // Only works for INSERT, UPDATE and DELETE query's
  202.     function _affectedrows()
  203.     {
  204.       $result =  @mysqli_affected_rows($this->_connectionID);
  205.       if ($result == -1) {
  206.           if ($this->debug) ADOConnection::outp("mysqli_affected_rows() failed : "  . $this->ErrorMsg());
  207.       }
  208.       return $result;
  209.     }
  210.   
  211.      // See http://www.mysql.com/doc/M/i/Miscellaneous_functions.html
  212.     // Reference on Last_Insert_ID on the recommended way to simulate sequences
  213.      var $_genIDSQL = "update %s set id=LAST_INSERT_ID(id+1);";
  214.     var $_genSeqSQL = "create table %s (id int not null)";
  215.     var $_genSeq2SQL = "insert into %s values (%s)";
  216.     var $_dropSeqSQL = "drop table %s";
  217.     
  218.     function CreateSequence($seqname='adodbseq',$startID=1)
  219.     {
  220.         if (empty($this->_genSeqSQL)) return false;
  221.         $u = strtoupper($seqname);
  222.         
  223.         $ok = $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  224.         if (!$ok) return false;
  225.         return $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  226.     }
  227.     
  228.     function GenID($seqname='adodbseq',$startID=1)
  229.     {
  230.         // post-nuke sets hasGenID to false
  231.         if (!$this->hasGenID) return false;
  232.         
  233.         $getnext = sprintf($this->_genIDSQL,$seqname);
  234.         $holdtransOK = $this->_transOK; // save the current status
  235.         $rs = @$this->Execute($getnext);
  236.         if (!$rs) {
  237.             if ($holdtransOK) $this->_transOK = true; //if the status was ok before reset
  238.             $u = strtoupper($seqname);
  239.             $this->Execute(sprintf($this->_genSeqSQL,$seqname));
  240.             $this->Execute(sprintf($this->_genSeq2SQL,$seqname,$startID-1));
  241.             $rs = $this->Execute($getnext);
  242.         }
  243.         $this->genID = mysqli_insert_id($this->_connectionID);
  244.         
  245.         if ($rs) $rs->Close();
  246.         
  247.         return $this->genID;
  248.     }
  249.     
  250.       function &MetaDatabases()
  251.     {
  252.         $query = "SHOW DATABASES";
  253.         $ret =& $this->Execute($query);
  254.         return $ret;
  255.     }
  256.  
  257.       
  258.     function &MetaIndexes ($table, $primary = FALSE)
  259.     {
  260.         // save old fetch mode
  261.         global $ADODB_FETCH_MODE;
  262.         
  263.         $save = $ADODB_FETCH_MODE;
  264.         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  265.         if ($this->fetchMode !== FALSE) {
  266.                $savem = $this->SetFetchMode(FALSE);
  267.         }
  268.         
  269.         // get index details
  270.         $rs = $this->Execute(sprintf('SHOW INDEXES FROM %s',$table));
  271.         
  272.         // restore fetchmode
  273.         if (isset($savem)) {
  274.                 $this->SetFetchMode($savem);
  275.         }
  276.         $ADODB_FETCH_MODE = $save;
  277.         
  278.         if (!is_object($rs)) {
  279.                 return FALSE;
  280.         }
  281.         
  282.         $indexes = array ();
  283.         
  284.         // parse index data into array
  285.         while ($row = $rs->FetchRow()) {
  286.                 if ($primary == FALSE AND $row[2] == 'PRIMARY') {
  287.                         continue;
  288.                 }
  289.                 
  290.                 if (!isset($indexes[$row[2]])) {
  291.                         $indexes[$row[2]] = array(
  292.                                 'unique' => ($row[1] == 0),
  293.                                 'columns' => array()
  294.                         );
  295.                 }
  296.                 
  297.                 $indexes[$row[2]]['columns'][$row[3] - 1] = $row[4];
  298.         }
  299.         
  300.         // sort columns by order in the index
  301.         foreach ( array_keys ($indexes) as $index )
  302.         {
  303.                 ksort ($indexes[$index]['columns']);
  304.         }
  305.         
  306.         return $indexes;
  307.     }
  308.  
  309.     
  310.     // Format date column in sql string given an input format that understands Y M D
  311.     function SQLDate($fmt, $col=false)
  312.     {    
  313.         if (!$col) $col = $this->sysTimeStamp;
  314.         $s = 'DATE_FORMAT('.$col.",'";
  315.         $concat = false;
  316.         $len = strlen($fmt);
  317.         for ($i=0; $i < $len; $i++) {
  318.             $ch = $fmt[$i];
  319.             switch($ch) {
  320.             case 'Y':
  321.             case 'y':
  322.                 $s .= '%Y';
  323.                 break;
  324.             case 'Q':
  325.             case 'q':
  326.                 $s .= "'),Quarter($col)";
  327.                 
  328.                 if ($len > $i+1) $s .= ",DATE_FORMAT($col,'";
  329.                 else $s .= ",('";
  330.                 $concat = true;
  331.                 break;
  332.             case 'M':
  333.                 $s .= '%b';
  334.                 break;
  335.                 
  336.             case 'm':
  337.                 $s .= '%m';
  338.                 break;
  339.             case 'D':
  340.             case 'd':
  341.                 $s .= '%d';
  342.                 break;
  343.             
  344.             case 'H': 
  345.                 $s .= '%H';
  346.                 break;
  347.                 
  348.             case 'h':
  349.                 $s .= '%I';
  350.                 break;
  351.                 
  352.             case 'i':
  353.                 $s .= '%i';
  354.                 break;
  355.                 
  356.             case 's':
  357.                 $s .= '%s';
  358.                 break;
  359.                 
  360.             case 'a':
  361.             case 'A':
  362.                 $s .= '%p';
  363.                 break;
  364.                 
  365.             default:
  366.                 
  367.                 if ($ch == '\\') {
  368.                     $i++;
  369.                     $ch = substr($fmt,$i,1);
  370.                 }
  371.                 $s .= $ch;
  372.                 break;
  373.             }
  374.         }
  375.         $s.="')";
  376.         if ($concat) $s = "CONCAT($s)";
  377.         return $s;
  378.     }
  379.     
  380.     // returns concatenated string
  381.     // much easier to run "mysqld --ansi" or "mysqld --sql-mode=PIPES_AS_CONCAT" and use || operator
  382.     function Concat()
  383.     {
  384.         $s = "";
  385.         $arr = func_get_args();
  386.         
  387.         // suggestion by andrew005@mnogo.ru
  388.         $s = implode(',',$arr); 
  389.         if (strlen($s) > 0) return "CONCAT($s)";
  390.         else return '';
  391.     }
  392.     
  393.     // dayFraction is a day in floating point
  394.     function OffsetDate($dayFraction,$date=false)
  395.     {        
  396.         if (!$date) 
  397.           $date = $this->sysDate;
  398.         return "from_unixtime(unix_timestamp($date)+($dayFraction)*24*3600)";
  399.     }
  400.     
  401.     function &MetaTables($ttype=false,$showSchema=false,$mask=false) 
  402.     {    
  403.         $save = $this->metaTablesSQL;
  404.         if ($showSchema && is_string($showSchema)) {
  405.             $this->metaTablesSQL .= " from $showSchema";
  406.         }
  407.         
  408.         if ($mask) {
  409.             $mask = $this->qstr($mask);
  410.             $this->metaTablesSQL .= " like $mask";
  411.         }
  412.         $ret =& ADOConnection::MetaTables($ttype,$showSchema);
  413.         
  414.         $this->metaTablesSQL = $save;
  415.         return $ret;
  416.     }
  417.     
  418.      function &MetaColumns($table) 
  419.     {
  420.         if (!$this->metaColumnsSQL)
  421.             return false;
  422.         
  423.         global $ADODB_FETCH_MODE;
  424.         $save = $ADODB_FETCH_MODE;
  425.         $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
  426.         if ($this->fetchMode !== false)
  427.             $savem = $this->SetFetchMode(false);
  428.         $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table));
  429.         if (isset($savem)) $this->SetFetchMode($savem);
  430.         $ADODB_FETCH_MODE = $save;
  431.         if (!is_object($rs))
  432.             return false;
  433.         
  434.         $retarr = array();
  435.         while (!$rs->EOF) {
  436.             $fld = new ADOFieldObject();
  437.             $fld->name = $rs->fields[0];
  438.             $type = $rs->fields[1];
  439.             
  440.             // split type into type(length):
  441.             $fld->scale = null;
  442.             if (preg_match("/^(.+)\((\d+),(\d+)/", $type, $query_array)) {
  443.                 $fld->type = $query_array[1];
  444.                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  445.                 $fld->scale = is_numeric($query_array[3]) ? $query_array[3] : -1;
  446.             } elseif (preg_match("/^(.+)\((\d+)/", $type, $query_array)) {
  447.                 $fld->type = $query_array[1];
  448.                 $fld->max_length = is_numeric($query_array[2]) ? $query_array[2] : -1;
  449.             } elseif (preg_match("/^(enum)\((.*)\)$/i", $type, $query_array)) {
  450.                 $fld->type = $query_array[1];
  451.                 $fld->max_length = max(array_map("strlen",explode(",",$query_array[2]))) - 2; // PHP >= 4.0.6
  452.                 $fld->max_length = ($fld->max_length == 0 ? 1 : $fld->max_length);
  453.             } else {
  454.                 $fld->type = $type;
  455.                 $fld->max_length = -1;
  456.             }
  457.             $fld->not_null = ($rs->fields[2] != 'YES');
  458.             $fld->primary_key = ($rs->fields[3] == 'PRI');
  459.             $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false);
  460.             $fld->binary = (strpos($type,'blob') !== false);
  461.             $fld->unsigned = (strpos($type,'unsigned') !== false);
  462.  
  463.             if (!$fld->binary) {
  464.                 $d = $rs->fields[4];
  465.                 if ($d != '' && $d != 'NULL') {
  466.                     $fld->has_default = true;
  467.                     $fld->default_value = $d;
  468.                 } else {
  469.                     $fld->has_default = false;
  470.                 }
  471.             }
  472.             
  473.             if ($save == ADODB_FETCH_NUM) {
  474.                 $retarr[] = $fld;
  475.             } else {
  476.                 $retarr[strtoupper($fld->name)] = $fld;
  477.             }
  478.             $rs->MoveNext();
  479.         }
  480.         
  481.         $rs->Close();
  482.         return $retarr;
  483.     }
  484.         
  485.     // returns true or false
  486.     function SelectDB($dbName) 
  487.     {
  488. //        $this->_connectionID = $this->mysqli_resolve_link($this->_connectionID);
  489.         $this->databaseName = $dbName;
  490.         if ($this->_connectionID) {
  491.             $result = @mysqli_select_db($this->_connectionID, $dbName);
  492.             if (!$result) {
  493.                 ADOConnection::outp("Select of database " . $dbName . " failed. " . $this->ErrorMsg());
  494.             }
  495.             return $result;        
  496.         }
  497.         return false;    
  498.     }
  499.     
  500.     // parameters use PostgreSQL convention, not MySQL
  501.     function &SelectLimit($sql,
  502.                   $nrows = -1,
  503.                   $offset = -1,
  504.                   $inputarr = false, 
  505.                   $arg3 = false,
  506.                   $secs = 0)
  507.     {
  508.         $offsetStr = ($offset >= 0) ? "$offset," : '';
  509.         if ($nrows < 0) $nrows = '18446744073709551615';
  510.         
  511.         if ($secs)
  512.             $rs =& $this->CacheExecute($secs, $sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
  513.         else
  514.             $rs =& $this->Execute($sql . " LIMIT $offsetStr$nrows" , $inputarr , $arg3);
  515.             
  516.         return $rs;
  517.     }
  518.     
  519.     
  520.     function Prepare($sql)
  521.     {
  522.         return $sql;
  523.         
  524.         $stmt = $this->_connectionID->prepare($sql);
  525.         if (!$stmt) {
  526.             echo $this->ErrorMsg();
  527.             return $sql;
  528.         }
  529.         return array($sql,$stmt);
  530.     }
  531.     
  532.     
  533.     // returns queryID or false
  534.     function _query($sql, $inputarr)
  535.     {
  536.     global $ADODB_COUNTRECS;
  537.         
  538.         if (is_array($sql)) {
  539.             $stmt = $sql[1];
  540.             $a = '';
  541.             foreach($inputarr as $k => $v) {
  542.                 if (is_string($v)) $a .= 's';
  543.                 else if (is_integer($v)) $a .= 'i'; 
  544.                 else $a .= 'd';
  545.             }
  546.             
  547.             $fnarr =& array_merge( array($stmt,$a) , $inputarr);
  548.             $ret = call_user_func_array('mysqli_stmt_bind_param',$fnarr);
  549.  
  550.             $ret = mysqli_stmt_execute($stmt);
  551.             return $ret;
  552.         }
  553.         if (!$mysql_res =  mysqli_query($this->_connectionID, $sql, ($ADODB_COUNTRECS) ? MYSQLI_STORE_RESULT : MYSQLI_USE_RESULT)) {
  554.             if ($this->debug) ADOConnection::outp("Query: " . $sql . " failed. " . $this->ErrorMsg());
  555.             return false;
  556.         }
  557.         
  558.         return $mysql_res;
  559.     }
  560.  
  561.     /*    Returns: the last error message from previous database operation    */    
  562.     function ErrorMsg() 
  563.       {
  564.         if (empty($this->_connectionID)) 
  565.           $this->_errorMsg = @mysqli_connect_error();
  566.         else 
  567.           $this->_errorMsg = @mysqli_error($this->_connectionID);
  568.         return $this->_errorMsg;
  569.       }
  570.     
  571.     /*    Returns: the last error number from previous database operation    */    
  572.     function ErrorNo() 
  573.       {
  574.         if (empty($this->_connectionID))  
  575.           return @mysqli_connect_errno();
  576.         else 
  577.           return @mysqli_errno($this->_connectionID);
  578.       }
  579.     
  580.     // returns true or false
  581.     function _close()
  582.       {
  583.         @mysqli_close($this->_connectionID);
  584.         $this->_connectionID = false;
  585.       }
  586.  
  587.     /*
  588.     * Maximum size of C field
  589.     */
  590.     function CharMax()
  591.     {
  592.         return 255; 
  593.     }
  594.     
  595.     /*
  596.     * Maximum size of X field
  597.     */
  598.     function TextMax()
  599.     {
  600.       return 4294967295; 
  601.     }
  602.  
  603.  
  604. }
  605.  
  606. /*--------------------------------------------------------------------------------------
  607.      Class Name: Recordset
  608. --------------------------------------------------------------------------------------*/
  609.  
  610. class ADORecordSet_mysqli extends ADORecordSet{    
  611.     
  612.     var $databaseType = "mysqli";
  613.     var $canSeek = true;
  614.     
  615.     function ADORecordSet_mysqli($queryID, $mode = false) 
  616.     {
  617.       if ($mode === false) 
  618.        { 
  619.           global $ADODB_FETCH_MODE;
  620.           $mode = $ADODB_FETCH_MODE;
  621.        }
  622.        
  623.       switch ($mode)
  624.         {
  625.         case ADODB_FETCH_NUM: 
  626.           $this->fetchMode = MYSQLI_NUM; 
  627.           break;
  628.         case ADODB_FETCH_ASSOC:
  629.           $this->fetchMode = MYSQLI_ASSOC; 
  630.           break;
  631.         case ADODB_FETCH_DEFAULT:
  632.         case ADODB_FETCH_BOTH:
  633.         default:
  634.           $this->fetchMode = MYSQLI_BOTH; 
  635.           break;
  636.         }
  637.       $this->adodbFetchMode = $mode;
  638.       $this->ADORecordSet($queryID);    
  639.     }
  640.     
  641.     function _initrs()
  642.     {
  643.     global $ADODB_COUNTRECS;
  644.     
  645.         $this->_numOfRows = $ADODB_COUNTRECS ? @mysqli_num_rows($this->_queryID) : -1;
  646.         $this->_numOfFields = @mysqli_num_fields($this->_queryID);
  647.     }
  648.     
  649.     function &FetchField($fieldOffset = -1) 
  650.     {    
  651.       $fieldnr = $fieldOffset;
  652.       if ($fieldOffset != -1) {
  653.         $fieldOffset = mysqli_field_seek($this->_queryID, $fieldnr);
  654.       }
  655.       $o = mysqli_fetch_field($this->_queryID);
  656.       return $o;
  657.     }
  658.  
  659.     function &GetRowAssoc($upper = true)
  660.     {
  661.       if ($this->fetchMode == MYSQLI_ASSOC && !$upper) 
  662.         return $this->fields;
  663.       $row =& ADORecordSet::GetRowAssoc($upper);
  664.       return $row;
  665.     }
  666.     
  667.     /* Use associative array to get fields array */
  668.     function Fields($colname)
  669.     {    
  670.       if ($this->fetchMode != MYSQLI_NUM) 
  671.         return @$this->fields[$colname];
  672.         
  673.       if (!$this->bind) {
  674.         $this->bind = array();
  675.         for ($i = 0; $i < $this->_numOfFields; $i++) {
  676.           $o = $this->FetchField($i);
  677.           $this->bind[strtoupper($o->name)] = $i;
  678.         }
  679.       }
  680.       return $this->fields[$this->bind[strtoupper($colname)]];
  681.     }
  682.     
  683.     function _seek($row)
  684.     {
  685.       if ($this->_numOfRows == 0) 
  686.         return false;
  687.  
  688.       if ($row < 0)
  689.         return false;
  690.  
  691.       mysqli_data_seek($this->_queryID, $row);
  692.       $this->EOF = false;
  693.       return true;
  694.     }
  695.         
  696.     // 10% speedup to move MoveNext to child class
  697.     // This is the only implementation that works now (23-10-2003).
  698.     // Other functions return no or the wrong results.
  699.     function MoveNext() 
  700.     {
  701.         if ($this->EOF) return false;
  702.         $this->_currentRow++;
  703.         $this->fields = @mysqli_fetch_array($this->_queryID,$this->fetchMode);
  704.         
  705.         if (is_array($this->fields)) return true;
  706.         $this->EOF = true;
  707.         return false;
  708.     }    
  709.     
  710.     function _fetch()
  711.     {
  712.         $this->fields = mysqli_fetch_array($this->_queryID,$this->fetchMode);  
  713.           return is_array($this->fields);
  714.     }
  715.     
  716.     function _close() 
  717.     {
  718.         mysqli_free_result($this->_queryID); 
  719.           $this->_queryID = false;    
  720.     }
  721.     
  722. /*
  723.  
  724. 0 = MYSQLI_TYPE_DECIMAL
  725. 1 = MYSQLI_TYPE_CHAR
  726. 1 = MYSQLI_TYPE_TINY
  727. 2 = MYSQLI_TYPE_SHORT
  728. 3 = MYSQLI_TYPE_LONG
  729. 4 = MYSQLI_TYPE_FLOAT
  730. 5 = MYSQLI_TYPE_DOUBLE
  731. 6 = MYSQLI_TYPE_NULL
  732. 7 = MYSQLI_TYPE_TIMESTAMP
  733. 8 = MYSQLI_TYPE_LONGLONG
  734. 9 = MYSQLI_TYPE_INT24
  735. 10 = MYSQLI_TYPE_DATE
  736. 11 = MYSQLI_TYPE_TIME
  737. 12 = MYSQLI_TYPE_DATETIME
  738. 13 = MYSQLI_TYPE_YEAR
  739. 14 = MYSQLI_TYPE_NEWDATE
  740. 247 = MYSQLI_TYPE_ENUM
  741. 248 = MYSQLI_TYPE_SET
  742. 249 = MYSQLI_TYPE_TINY_BLOB
  743. 250 = MYSQLI_TYPE_MEDIUM_BLOB
  744. 251 = MYSQLI_TYPE_LONG_BLOB
  745. 252 = MYSQLI_TYPE_BLOB
  746. 253 = MYSQLI_TYPE_VAR_STRING
  747. 254 = MYSQLI_TYPE_STRING
  748. 255 = MYSQLI_TYPE_GEOMETRY
  749. */
  750.  
  751.     function MetaType($t, $len = -1, $fieldobj = false)
  752.     {
  753.         if (is_object($t)) {
  754.             $fieldobj = $t;
  755.             $t = $fieldobj->type;
  756.             $len = $fieldobj->max_length;
  757.         }
  758.         
  759.         
  760.          $len = -1; // mysql max_length is not accurate
  761.          switch (strtoupper($t)) {
  762.          case 'STRING': 
  763.          case 'CHAR':
  764.          case 'VARCHAR': 
  765.          case 'TINYBLOB': 
  766.          case 'TINYTEXT': 
  767.          case 'ENUM': 
  768.          case 'SET': 
  769.         
  770.         case MYSQLI_TYPE_TINY_BLOB :
  771.         case MYSQLI_TYPE_CHAR :
  772.         case MYSQLI_TYPE_STRING :
  773.         case MYSQLI_TYPE_ENUM :
  774.         case MYSQLI_TYPE_SET :
  775.         case 253 :
  776.            if ($len <= $this->blobSize) return 'C';
  777.            
  778.         case 'TEXT':
  779.         case 'LONGTEXT': 
  780.         case 'MEDIUMTEXT':
  781.            return 'X';
  782.         
  783.         
  784.            // php_mysql extension always returns 'blob' even if 'text'
  785.            // so we have to check whether binary...
  786.         case 'IMAGE':
  787.         case 'LONGBLOB': 
  788.         case 'BLOB':
  789.         case 'MEDIUMBLOB':
  790.         
  791.         case MYSQLI_TYPE_BLOB :
  792.         case MYSQLI_TYPE_LONG_BLOB :
  793.         case MYSQLI_TYPE_MEDIUM_BLOB :
  794.         
  795.            return !empty($fieldobj->binary) ? 'B' : 'X';
  796.         case 'YEAR':
  797.         case 'DATE': 
  798.         case MYSQLI_TYPE_DATE :
  799.         case MYSQLI_TYPE_YEAR :
  800.         
  801.            return 'D';
  802.         
  803.         case 'TIME':
  804.         case 'DATETIME':
  805.         case 'TIMESTAMP':
  806.         
  807.         case MYSQLI_TYPE_DATETIME :
  808.         case MYSQLI_TYPE_NEWDATE :
  809.         case MYSQLI_TYPE_TIME :
  810.         case MYSQLI_TYPE_TIMESTAMP :
  811.         
  812.             return 'T';
  813.         
  814.         case 'INT': 
  815.         case 'INTEGER':
  816.         case 'BIGINT':
  817.         case 'TINYINT':
  818.         case 'MEDIUMINT':
  819.         case 'SMALLINT': 
  820.         
  821.         case MYSQLI_TYPE_INT24 :
  822.         case MYSQLI_TYPE_LONG :
  823.         case MYSQLI_TYPE_LONGLONG :
  824.         case MYSQLI_TYPE_SHORT :
  825.         case MYSQLI_TYPE_TINY :
  826.         
  827.            if (!empty($fieldobj->primary_key)) return 'R';
  828.            
  829.            return 'I';
  830.         
  831.         
  832.            // Added floating-point types
  833.            // Maybe not necessery.
  834.          case 'FLOAT':
  835.          case 'DOUBLE':
  836.            //        case 'DOUBLE PRECISION':
  837.          case 'DECIMAL':
  838.          case 'DEC':
  839.          case 'FIXED':
  840.          default:
  841.              //if (!is_numeric($t)) echo "<p>--- Error in type matching $t -----</p>"; 
  842.              return 'N';
  843.         }
  844.     } // function
  845.     
  846.  
  847. } // rs class
  848.  
  849. }
  850.  
  851. ?>